package com.example.demo.controller;

import com.example.demo.domain.User;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

/**
 * @Author Yimka
 * @Date 2017/11/8 14:36
 */
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @PutMapping("/user")
    public String addUser(){
        User user=  new User();
        user.setAge(18);
        user.setUsername("王尼玛");
        user.setId(UUID.randomUUID().toString());
        user.setPassword("12344321");

        userService.save(user);

        return user.getId();
    }

    @GetMapping("/users")
    public List<User> list(){
        return userService.listAll();
    }

    @GetMapping("/user")
    public User selectUser(@RequestBody String id){
        User user = userService.queryById(id);
        return user;
    }


}
